package com.code.Factorial;

/**
 * Username : YouQiRong
 * Date : 2025/5/19 20:49
 * Class: 插入排序
 */
public class InsertSort {
    public static void insertSort(int[] a) {
        insert(a,1);
    }

    private static void insert(int[] a, int low){
        if (low == a.length){
            return;
        }

        int t = a[low];
        int i = low -1;//已排序区域指针

        while (i >= 0 && a[i] > t){ //没有找到插入位置
            a[i+1] = a[i]; //空出插入位置
            i--;
        }
        //找到插入位置
        a[i+1] = t;

        insert(a,low + 1);
    }
}
